package com.example.lijianwen.startproject_401ljw;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.lijianwen.startproject_401ljw.bean.Weatherinfo;
import com.example.lijianwen.startproject_401ljw.iface.WeatherListener;
import com.example.lijianwen.startproject_401ljw.model.Weather51Model;
import com.example.lijianwen.startproject_401ljw.model.WeatherModel;

import org.w3c.dom.Text;

public class MainActivity extends AppCompatActivity implements WeatherListener, View.OnClickListener{

    private EditText etcityno;
    private Button btnfind1,btnfind2;
    private TextView tvcityname;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init(){
        etcityno = (EditText)findViewById(R.id.addressno);
        btnfind1 = (Button)findViewById((R.id.find1));
        btnfind2 = (Button)findViewById(R.id.find2);
        tvcityname=(TextView)findViewById(R.id.textView3);

        btnfind1.setOnClickListener(this);
        btnfind2.setOnClickListener(this);
    }

    @Override
    public void onResonse(Weatherinfo weatherInfo) {
        if(weatherInfo!=null){
            tvcityname.setText(weatherInfo.getCity());
        }
        else
        {
            tvcityname.setText("未知");
        }

    }

    @Override
    public void onFail(String msg) {
        tvcityname.setText(msg);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.find1:
                System.out.println("点击按钮weather");
                WeatherModel weatherModel = new WeatherModel();
                weatherModel.getWeather(etcityno.getText().toString(), this);
                break;
            case R.id.find2:
                System.out.println("点击按钮weather51");
                Weather51Model weather51Model = new Weather51Model();
                weather51Model.getWeather(etcityno.getText().toString(), this);
                break;
        }
    }
}
